/*=======================================================================
 *Subsystem:   no-real-time
 *File:        task.h
 *Author:      ZhangWenbo
 *Description:
 ========================================================================
 * History:
 * 1. Date:
      Author:
      Modification:
========================================================================*/
#ifndef TASK_FUN_
#define TASK_FUN_

#define  ON_SYSTEST    1        
#define  OFF_SYSTEST   0    
#define  SYSTASK_SWITCH  OFF_SYSTEST

#define MAXNUMTASK     48                   /* usable task number */
#define NOTASK_PRIO    0                    /* reserve priority  */
#define STATTASK_PRIO  (MAXNUMTASK - 2)     /* statistics task priority */
#define IDLETASK_PRIO  (MAXNUMTASK - 1)     /* idle task priority  */
#define REAL_NUM_TASK  (MAXNUMTASK - 2)     /* real use task number */
#define TASKRUN          1                  /* task start run */
#define TASKSTOP         0                  /* task stop  */
#define TIMETICK         1                  /* time tick:  millisecond */
                                     
#define  OS_STAT_RDY            0x00        /* Ready to run */
#define  OS_STAT_SEM            0x01        /* Pending on semaphore */
#define  OS_STAT_MBOX           0x02        /* Pending on mailbox */
#define  OS_STAT_Q              0x04        /* Pending on queue */
#define  OS_STAT_SUSPEND        0x08        /* Task is suspended */
#define  OS_STAT_MUTEX          0x10        /* Pending on mutual exclusion semaphore */
#define  OS_STAT_FLAG           0x20        /* Pending on event flag group */

#define  OS_STAT_MASKSEM        0xFE        /* Pending on semaphore */
#define  OS_STAT_MASKMBOX       0xFD        /* Pending on mailbox */
#define  OS_STAT_MASKQ          0xFB        /* Pending on queue   */
#define  OS_STAT_MASKSUSPEND    0xF7        /* Pending on task */  
#define  OS_STAT_MASKMUTEX      0xEF        /* Pending on mutual exclusion semaphore */
#define  OS_STAT_MASKFLAG       0xDF        /* Pending on event flag group */  

typedef enum 
{
   TASK_NOERROR,
   TASK_ERROR,
   TASKPRIO_INVALID,
   TASKPRIO_USED,
   TASKPRIO_NOCREAT
}TaskState_e;

typedef struct Task_TypeDef                
{
    void (*handle)(void);                  /* task function */
    unsigned char flag;                    /* task priority */
    unsigned short int masktime;           /* period */
    unsigned short int timecount;          /* timer tick*/
    unsigned short int maskofftime;        /* offset time */
    unsigned short int offtimecount;       /* offset time tick */
    unsigned       int taskcount;          /* offset time timer */
    unsigned char status;                  /* task state */
}TASK;
extern TASK task[MAXNUMTASK];
extern unsigned char TaskRoll(void);
extern void TimeTick(void);
extern unsigned char TaskCreate(void (*Handle)(), unsigned char prio, unsigned short int perTime, unsigned short int offTime);
extern unsigned char TaskResume (unsigned char prio); 
extern unsigned char TaskSuspend  (unsigned char prio);
extern unsigned char TaskDel(unsigned char prio);
extern unsigned char  TaskChangePrio (unsigned char oldprio, unsigned char newprio);
extern void  TaskStat(void);
extern void  TaskIdle (void);
extern void  TaskParaInit (void);
extern void  AppTaskCreate(void);
extern void ProjectTaskCreat(void);
   
#endif

